﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo.Lib {
    public class ChineseConverter {
        private IConversionMappingStrategy mappingStrategy;

        public ChineseConverter(IConversionMappingStrategy mappingStrategy = null) {
            this.mappingStrategy = mappingStrategy;
        }

        public void Convert(Stream input, string filename, IConversionMappingStrategy mappingStrategy = null) {
            if (mappingStrategy == null) {
                mappingStrategy = this.mappingStrategy;
            }

            File.Delete(filename);
            StreamReader reader = new StreamReader(input);
            using (var writer = new StreamWriter(File.OpenWrite(filename), Encoding.UTF8))
            foreach (var line in mappingStrategy.Convert(reader)){
                writer.WriteLine(line);
            }
        }
    }
}
